package wahadlo.nowe.controllers;

import wahadlo.nowe.model.Model;
import wahadlo.nowe.model.ModelRecipient;

/**
 * 
 * @author Koziołek
 * 
 */
public class AxisController implements Controller {

	private Model model;
	private ModelRecipient modelRecipient;
	private Double length;
	private Double weight;
	private Double inclination;
	private DataValidator validator;
	private AnimationImpl animationImpl;
	private String chartType;
	private Double forcing;

	public AxisController() {
		validator = new DataValidatorImpl();
	}

	public boolean bind() {
		length = (Double) model.getProperties().get("length");
		weight = (Double) model.getProperties().get("weight");
		inclination = (Double) model.getProperties().get("inclination");
		chartType = (String) model.getProperties().get("chartType");
		forcing = (Double)model.getProperties().get("forcing");
		return validate();
	}

	private boolean validate() {
		if (chartType == null)
			return false;
		if(forcing>1.)
			return false;
		return validator.absoluteGreatThanZero(inclination)
				&& validator.greatThanZero(weight)
				&& validator.greatThanZero(length);
	}

	public void process() {
		animationImpl = new AnimationImpl(model, modelRecipient);
		Thread thread = new Thread(animationImpl);
		animationImpl.setRunnig(true);
		thread.start();
	}

	public void putModel(Model model) {
		this.model = model;
	}

	public void putRecipient(ModelRecipient modelRecipient) {
		this.modelRecipient = modelRecipient;
	}

	public Animation getAnimation() {
		return animationImpl;
	}

}